//
//  StaticVariables.m
//  LabanBrowser
//
//  Created by -Xh- on 3/9/13.
//  Copyright (c) 2013 VNG. All rights reserved.
//

#import "StaticVariables.h"


@implementation StaticVariables{
    
}

@synthesize dbPath;
@synthesize userDefaults;
@synthesize presetThemes;
@synthesize constantValues;
@synthesize historyAccess;
@synthesize bookmarkAccess;
@synthesize speedDialAccess;
@synthesize presetDialerURLDic;
@synthesize editorView;
@synthesize settingsData;
@synthesize currentSettingsType;
+(id)shareVariables{
    static StaticVariables *staticVariables=nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        staticVariables=[[StaticVariables alloc]init];
    });
    return staticVariables;
}


- (id)init
{
    self = [super init];
    if (self) {
        userDefaults = [[UserDefaults alloc]init];
        constantValues = [[ConstantValues alloc]init];
        presetThemes=[[NSMutableArray alloc]init];
        //settingsData = [[SettingsDataProvider alloc]init];
        self.currentSettingsType = SettingsNone;
        [presetThemes addObject:[UIColor clearColor]];
        [presetThemes addObject:[UIColor blueColor]];
        [presetThemes addObject:[UIColor greenColor]];
        [presetThemes addObject:[UIColor purpleColor]];
        [presetThemes addObject:[UIColor redColor]];
        [presetThemes addObject:[UIColor orangeColor]];
        [presetThemes addObject:[UIColor yellowColor]];
        
        presetDialerURLDic=[[NSMutableDictionary alloc]init];//
        [presetDialerURLDic setObject:@"dial_google.png" forKey:@"http://www.google.com.vn/" ];
        [presetDialerURLDic setObject:@"dial_facebook.png" forKey:@"http://www.facebook.com/" ];
        [presetDialerURLDic setObject:@"dial_gmail.png"  forKey:@"https://mail.google.com/" ];
        [presetDialerURLDic setObject:@"dial_yahoo.png" forKey:@"http://mail.yahoo.com/"];
        [presetDialerURLDic setObject:@"dial_youtube.png"  forKey:@"http://www.youtube.com/"];
        [presetDialerURLDic setObject:@"dial_zing_mp3.png"  forKey:@"http://mp3.zing.vn/"];
        
        //editorView = [[[NSBundle mainBundle]loadNibNamed:@"EditorView" owner:self options:nil]objectAtIndex:0];
        //[editorView initialize];
    }
    return self;
}
-(void)dealloc{
    dbPath=nil;
}
-(void)initBonusStuffs{
    settingsData = [[SettingsDataProvider alloc]init];
    editorView = [[[NSBundle mainBundle]loadNibNamed:@"EditorView" owner:self options:nil]objectAtIndex:0];
    [editorView initialize];
}

-(void)initAccess{
    historyAccess = [[HistoryAccess alloc]initWithDatabasePath:dbPath];
    bookmarkAccess = [[BookmarkAccess alloc]initWithDatabasePath:dbPath];
    speedDialAccess = [[SpeedDialAccess alloc]initWithDatabasePath:dbPath];
}

-(NSArray *)getAppropriateArrayForType:(SettingsChooserType)_chooserType{
    NSArray* resultArray;
    switch (_chooserType) {
        case SettingsTextSize:
            resultArray = [settingsData textSize];
            break;
            
        case SettingsDefaultZoom:
            resultArray = [settingsData defaultZoom];
            break;
        case SettingsUserAgent:
            resultArray = [settingsData userAgents];
            break;
        case SettingsOrientation:
            resultArray = [settingsData orientation];
            break;
        case SettingsCheckUpdates:
            resultArray = [settingsData checkUpdates];
            break;
        case SettingsNone:
            resultArray = nil;
            break;
        case SettingsLanguage:
            resultArray = [settingsData language];
            break;
    }
    return resultArray;
}

-(NSArray *)getAppropriateArray{
    return [self getAppropriateArrayForType:currentSettingsType];
}
-(int)currentIndexOfSettingsChooser{
    int resultValue;
    switch (currentSettingsType) {
        case SettingsTextSize:{
            resultValue = [[[self userDefaults]webFontSize]intValue];
        }
            break;
            
        case SettingsDefaultZoom:
            resultValue = [[[self userDefaults]webZoomScale]intValue];
            break;
        case SettingsUserAgent:
            resultValue = [[[self userDefaults]webUserAgent]intValue];
            break;
        case SettingsOrientation:
            resultValue = [[[self userDefaults]orientation]intValue];
            break;
        case SettingsCheckUpdates:
            resultValue = [[[self userDefaults]howOftenToCheckForUpdate]intValue];
            break;
        case SettingsNone:
            resultValue = -1;
            break;
        case SettingsLanguage:
            resultValue = [[[self userDefaults]language]intValue];
            break;
    }
    return resultValue;
}
@end
